package hmvictor.jpql;

import hmvictor.jpql.types.ParameterType;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Victor
 */
public class ParameterCache {
    private final Map<String, CacheValue> namedParameters=new HashMap<>();
    private final Map<Integer, CacheValue> positionalParameters=new HashMap<>();
    
    public <T> void put(String name, ParameterType<T> type, T value){
        namedParameters.put(name, new CacheValue(type, value));
    }
    
    public <T> CacheValue<T> get(String name) {
        return namedParameters.get(name);
    }
    
    public boolean contains(String name){
        return namedParameters.containsKey(name);
    }
    
    public <T> void put(int position, ParameterType<T> type, T value){
        positionalParameters.put(position, new CacheValue(type, value));
    }
    
    public <T> CacheValue<T> get(int position) {
        return positionalParameters.get(position);
    }
    
    public boolean contains(int position){
        return positionalParameters.containsKey(position);
    }
    
    public static class CacheValue<T>{
        private ParameterType<T> type;
        private T value;

        public CacheValue(ParameterType<T> type, T value) {
            this.type = type;
            this.value = value;
        }

        public ParameterType<T> getType() {
            return type;
        }

        public void setType(ParameterType<T> type) {
            this.type = type;
        }

        public T getValue() {
            return value;
        }

        public void setValue(T value) {
            this.value = value;
        }
        
    }
    
}
